package logic

import (
	"context"
	"fmt"
	"project/model/redis"

	"project/projectrpc/internal/svc"
	"project/projectrpc/projectrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VailUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVailUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VailUserLogic {
	return &VailUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *VailUserLogic) VailUser(in *projectrpc.VailUserRequest) (*projectrpc.VailUserResponse, error) {
	// todo: add your logic here and delete this line

	capt := redis.Rdb.Get("captcha" + in.Source + in.Tel)
	if capt.Val() == "" {
		return nil, fmt.Errorf("暂未获取图形验证码")
	}
	if capt.Val() != in.Captcha {
		return nil, fmt.Errorf("图形验证码输入错误")
	}

	send := redis.Rdb.Get("sendSms" + in.Source + in.Tel)
	if send.Val() == "" {
		return nil, fmt.Errorf("暂未获取短信验证码")
	}
	if send.Val() != in.SendSms {
		return nil, fmt.Errorf("短信验证码输入错误")
	}

	return &projectrpc.VailUserResponse{}, nil
}
